import time
from appium import webdriver
from appium.options.android import UiAutomator2Options
from selenium.webdriver.common.by import By

from page import xw

class GetDriver:
    @staticmethod
    def Device():
        capabilities = dict(
            platformName='Android',
            automationName='uiautomator2',
            deviceName='Android',
            appPackage='com.android.launcher3',
            appActivity='com.android.launcher3.Launcher',
            # noReset=True  # 设置 noReset 为 true
        )
        driver = webdriver.Remote(command_executor=xw.url, options=UiAutomator2Options().load_capabilities(capabilities))
        return driver

if __name__ == '__main__':
    get_device = GetDriver()
    driver = get_device.Device()
    driver.find_element(By.XPATH, "//android.widget.TextView[@text='商城app' and @content-desc='商城app']").click()
    time.sleep(10)
    driver.quit()